<template>
      <a-form :model="formParams" ref="formRef" auto-label-width :rules="rules">
        <template v-if="changeType === 'leave'">
            <a-form-item label="离职时间:" field="disableTime">
                <a-date-picker showTime v-model="formParams.disableTime" />
            </a-form-item>
        </template>
        <template v-else-if="changeType === 'password'">
            <a-form-item label="密码:" field="password">
                <a-input-password v-model.trim="formParams.password" placeholder="请输入密码" />
            </a-form-item>
        </template>
        <template v-else-if="changeType === 'deptManager'">
            <a-form-item label="部门:" field="deptId">
                <a-tree-select v-model="formParams.deptId" placeholder="请选择部门" :data="currentNode.deptList" allow-clear  allow-search  :tree-check-strictly="true" :fieldNames="{key:'id',title:'name'}">
					<!-- <a-option v-for="item in deptList" :key="item.id" :label="item.label" :value="item.id" /> -->
				</a-tree-select>
            </a-form-item>
        </template>
    </a-form>
</template>
<script lang="ts" setup>
import * as Api from '@/api/common';
import mixins from '@/mixins/index.js';
const { handleMixinSubmit } = mixins();
const props=defineProps({
    changeType:{type:String,},//leave:用户离职;password:密码修改;deptManager:设置部门负责人
    userId:{type:Array,default:()=>[]},//当前选择用户Id
    currentNode: { type: Object, default: () => { return {} } },
});
const emit=defineEmits(['refreshList'])
const formParams=ref({
    disableTime:'',
    password:'',
    deptId:''
});
const rules=reactive({
    disableTime: [{ required: true, message: "离职时间不能为空", trigger: "blur" }],
    password : [{ required: true, message: "密码不能为空", trigger: "change" }],
    deptId : [{ required: true, message: "部门不能为空", trigger: "change" }],
});
const handleSubmit=async ()=>{
    const {disableTime,password,deptId}=formParams.value
    if(props.changeType=='leave'){
        const params={
            id:props.userId[0],
            disableTime
        }
       
        await handleMixinSubmit(Api.ApiUserDisable, params, emit('refreshList'), false);
    }else if(props.changeType=='password'){
        const params={
            id:props.userId[0],
            password
        }
        await handleMixinSubmit(Api.ApiUserPassword, params, emit('refreshList'), false);
    }else {
        const params={
            userId:props.userId,
            id:deptId
        };

        console.log(params,'params');
        
        // return
        await handleMixinSubmit(Api.ApiManager, params, emit('refreshList'), false);
    }
};
defineExpose({
    handleSubmit
})
</script>
